import { createRouter, createWebHistory, RouteRecordRaw } from "vue-router";
import login from "@/views/login/login.vue";
import Home from "@/layout/index.vue";
import Screen from "@/views/screen/index.vue";

const routes: Array<RouteRecordRaw> = [
  {
    path: "/",
    name: "login",
    component: login,
  },
  {
    path: "/login",
    name: "login",
    component: login,
  },
  {
    path: "/home",
    name: "Home",
    component: Home,
  },
  {
    path: "/screen",
    name: "Screen",
    component: Screen,
  },
];

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes,
});

// 默认路由重定向
router.beforeEach((to, from, next) => {
  if (to.path === "/") {
    next("/login"); // 假设你的默认路由是 /login
  } else {
    next();
  }
});

export default router;
